package com.example.booklist.mapper;

import com.example.booklist.model.BookInfo;
import com.example.booklist.model.PageRequest;
import com.example.booklist.model.PageResult;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Component
@Mapper
public interface BookInfoMapper {

    @Select("select* from book_info where id = #{id}")
    BookInfo selectBookById(Integer id);

    Integer updateBookById(BookInfo bookInfo);

    @Delete("update book_info set status = #{status} where id = #{id}")
    Integer deleteBookById(BookInfo bookInfo);

    @Insert("insert into book_info(book_name,author,count,price,publish,status) " +
            "values(#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    @Select("select * from book_info where status != 0 limit #{pageSize} offset #{offset}")
    List<BookInfo> selectBooksByPage(Integer pageSize, Integer offset);

    @Select("select count(id) from book_info")
    Integer total();

    Integer batchDeleteBook(List<Integer> ids);
}
